package com.example.javamaday.graph;

/**
 * 加权无向图的边
 */
public class Edge implements Comparable<Edge> {

    private final int v; // 顶点 v
    private final int w; // 顶点 w
    private final double weight;  // 当前边的权重

    public Edge(int v, int w, double weight) {
        this.v = v;
        this.w = w;
        this.weight = weight;
    }

    public double weight() {
        return weight;
    }

    // 获取边上的一个点
    public int either() {
        return v;
    }

    // 获取边上的另一个点
    public int other(int vertex) {
        if (vertex == v) {
            return w;
        } else {
            return v;
        }
    }

    @Override
    public int compareTo(Edge that) {
        int cmp;
        if (this.weight() > that.weight()) {
            cmp = 1;
        } else if (this.weight() < that.weight()) {
            cmp = -1;
        } else {
            cmp = 0;
        }
        return cmp;
    }
}
